<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2022/12/4
  Time: 13:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>$Title$</title>
    <script type="text/javascript" src="/05SpringMVC/js/jquery.js"></script>
  </head>
  <body>
        <button id="btn1">请求字符串</button><br>
        <button id="btn2">请求json格式的字符串</button>
        <button id="btn3">请求json对象</button>
        <button id="btn4">请求json格式字符串数组</button>
        <button id="btn5">查询的数据</button>
        <div>
            <c:forEach items="${users}" var="user">
                id:${user.userId}--
                用户名:${user.userName}--
                密码：${user.password}--
                年龄：${user.userAge}<br>
            </c:forEach>
        </div>

  </body>
  <script>
    $("#btn1").click(function(){
      $.ajax({
        url:"/05SpringMVC/btn1",
        type:"POST",
        data:"hezongda",
        contentType:"appliction/json",
        success:function (data){
          console.log(data)
        }
      })
    })

    $("#btn2").click(function(){
        console.log("111");
      $.ajax({
        url:"/05SpringMVC/btn2",
        type:"POST",
        data:'{"userName":"zhangsan","password":"123456"}',
        success:function (data){
          console.log(data)
        },
        contentType:"appliction/json"

      })

    })

    $("#btn3").click(function(){
        $.ajax({
            url:"/05SpringMVC/btn3",
            type:"get",
            data: {
                "userName":"zhangsan",
                "password":"123456"
            },
            success:function (data){
                console.log(data)
            },

        })

    })

    $("#btn4").click(function(){

        $.ajax({
            url:"/05SpringMVC/btn4",
            type:"POST",
            data:'[{"userName":"zhangsan","password":123456},{"userName":"lisi","password":123456}]',
            success:function(data){
                console.log(data);
            },
            contentType:"application/json"
        })
    })
    $("#btn5").click(function(){

        $.ajax({
            url:"/05SpringMVC/btn5",
            type:"POST",
            success:function(data){
                console.log(data);

                location.reload();
            },
            contentType:"application/json"
        })
    })
  </script>
</html>
